package com.cxx.purchasecharge.dal.impl;

import java.util.List;

import javax.persistence.Query;

import com.cxx.purchasecharge.core.model.persistence.OrderItem;
import com.cxx.purchasecharge.dal.OrderItemDao;
import com.cxx.purchasecharge.dal.common.MyGenericDaoImpl;

public class OrderItemDaoImpl extends MyGenericDaoImpl<OrderItem, Long> implements OrderItemDao {

	public OrderItemDaoImpl() {
		super(OrderItem.class);
	}

	@Override
	public List<OrderItem> findByOrder(long orderId) {
		String sql = "select o from OrderItem o join fetch o.order where o.order.id=?1";
		Query query = getEntityManager ().createQuery (sql, OrderItem.class);
		query.setParameter (1, orderId);
		return query.getResultList ();
	}

	@Override
	public List<OrderItem> findByGoods(long goodsId) {
		String sql = "select o from OrderItem o where o.goods.id=?1";
		Query query = getEntityManager ().createQuery (sql, OrderItem.class);
        query.setParameter (1, goodsId);
        return query.getResultList ();
	}

}
